import * as service from "@/service";
import { IRegister } from "./interface";
import { Dialog } from "vant";
const register: IRegister = {
  actions: {
    async register({ commit }, { values }) {
      const res: { status?: number; msg?: string } =
        await service.fetchRegister(values);
      switch (res.status) {
        case 0:
          Dialog.alert({
            message: res?.msg,
          });
          break;
        case 1:
          Dialog.confirm({
            message: res?.msg + "，是否跳转到登录页",
          })
            .then(() => {
              location.href = "/login";
            })
            .catch(() => {
              // on cancel
            });
          break;
        default:
          Dialog.alert({
            message: "发生未知错误",
          });
          break;
      }
      commit({
        type: "REGISTER",
        payload: res,
      });
    },
  },
  namespaced: true,
};
export default register;
